using System;
using System.IO;

namespace MyDesigner
{
	public static class Logger
	{
		private static string logDir;
		private static string logFile;
		private static object typeLock = new object();

		static Logger()
		{
			try
			{
				logDir = 
					Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), 
					             "MyDesigner");

				if (!Directory.Exists(logDir))
					Directory.CreateDirectory(logDir);

				logFile = Path.Combine(logDir, "log.txt");
			}
			catch (Exception)
			{
				//TODO: We can use Trace class here.
			}
		}

		public static void Log(string message)
		{
			try
			{
				lock (typeLock)
				{
					using (StreamWriter sw = new StreamWriter(logFile, true))
					{
						sw.WriteLine("{0} {1}", DateTime.Now, message);
					}
				}
			}
			catch(Exception)
			{
				//TODO: We can use Trace class here.
			}
		}
	}
}